[SDK/Factories] Add argsSchema To The Factory Authoring Surface - #2315
Conversation
FactoryMeta now declares an optional argsSchema, typed as the existing FactoryJsonSchema. The field already crossed the wire because defineFactory snapshots meta whole, so this is additive and type-level: it makes a runtime feature discoverable to extension authors writing against the published types. Without a declared schema nothing validates a caller's args. A malformed call starts a run, takes a user approval, spends credits, and then fails inside the factory body. With one, the CLI rejects it before the run row exists and the model retries against a correction hint. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Exposes factory argument schemas in the Node.js SDK and documents their runtime validation behavior.
Changes:
- Adds optional
FactoryMeta.argsSchema. - Documents supported schema constraints.
- Adds unit and E2E coverage for schema transport.
Show a summary per file
| File | Description |
|---|---|
nodejs/src/types.ts |
Adds the public metadata field. |
nodejs/src/factory.ts |
Expands schema documentation. |
nodejs/docs/factories.md |
Documents argument schemas and usage. |
nodejs/test/factory.test.ts |
Tests freezing, serialization, and documentation. |
nodejs/test/e2e/fixtures/factory-extension.mjs |
Adds a schema to the E2E fixture. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Balanced
Enforcement lives behind toolRunFactoryValidateArgs, which the runtime calls only from runFactoryTool. session.factory.run does not validate, so the docs and JSDoc now say which caller is checked instead of implying all of them are. The argument-echo fixture declared ["object","null"] while its contract is to echo any JsonValue, and it is invoked with an array. Nothing broke, because the SDK path does not validate, but the narrow declaration was dishonest and would have become load-bearing if that path ever gained validation. Widened it to the factory's real contract and corrected the comment, which claimed the fixture exercised enforcement when it only exercises registration. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Cross-SDK Consistency Review ✅This PR adds Finding: No cross-SDK consistency issues. The Agent Factories feature ( The changes are internally consistent:
No action required in other SDKs.
|
What
FactoryMetanow declares an optionalargsSchema, so an extension author can state the argument shape their factory expects.It reuses the existing
FactoryJsonSchematype. That type already documents the same bounded subset the CLI enforces, and the runtime's own validator points at it as the contract boundary.The field already crossed the wire, because
defineFactorysnapshotsmetawhole rather than cherry-picking fields. This change is additive and type-level. It makes an existing runtime feature discoverable to authors writing against the published types.Docs and JSDoc now describe what a declaration enforces, matching the
run_factorytool description word for word.Why
Almost no factory declares an argument shape, because the SDK never exposed the field. Authors reading the published types cannot tell the feature exists.
That has a real cost. Without a declared schema nothing validates a caller's
args. A malformed call starts a run, takes a user approval, spends credits, and then dies inside the factory body with a confusing error about a missing property.With a declared schema the CLI catches the mismatch before the run starts. The model gets a correction hint and retries. No run row, no permission prompt, no credit spend.
Notes
nodejs/src/types.tsis hand-written, not generated. It already importsJsonValuefromfactory.ts, so importingFactoryJsonSchemaalongside it follows the established convention.argsSchemais optional. A factory that omits it behaves exactly as before, which a unit test asserts.run_factory-path only. The runtime callstoolRunFactoryValidateArgsfromrunFactoryTooland nowhere else, sosession.factory.run(...)is not validated. The docs and JSDoc say so explicitly, and a doc test pins that caveat, because an author would otherwise reasonably assume their own SDK-initiated runs were checked.Testing
argsSchemasurvivesdefineFactory, is deep-frozen, serializes to JSON, and reaches thesession.resumeregistration payload. It also asserts an omitting factory carries no such property.run_factorytool cannot drift apart.argument-echoE2E fixture declares a schema, proving a declaration registers against a live runtime. It does not prove enforcement, since the E2E drives the SDK path.nodejsunit suite,typecheck,lint, andformat:checkall pass. Threefactory.e2efailures are pre-existing and reproduce identically on a clean tree.